﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eShop.Model;
using eShop.DataAccess;

public partial class write_review : System.Web.UI.Page
{
    public Int32 _ProductId
    {
        get
        {
            try
            {
                if (HttpContext.Current.Request.QueryString != null && !string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["id"]))
                {
                    return Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]);
                }
                else
                {
                    return -1;
                }
            }
            catch
            {
                return -1;
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            uccResponseMessage.SetNoticeMessage("Please write your review.");
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        ProductReview _review = new ProductReview();
        _review.ProductId = _ProductId;
        _review.ReviewDate = DateTime.Now;
        _review.CustomerName = txtName.Text.Trim();
        _review.CustomerEmail = txtEmail.Text.Trim();
        _review.ReviewText = txtReview.Text.Trim();
        _review.IsApproved = false;
        
        _review.RatingValue = Convert.ToDecimal(hidRate.Value.Trim());
        if (ProductReviewDAO.Save(_review))
        {
            uccResponseMessage.SetSuccessMessage("Thnaks for submitting the review.");
        }
        else
        {
            uccResponseMessage.SetSuccessMessage("Review submitting failed.");
        }
    }
}